package pkg.hicph.org;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;


public class PlaceDialog extends Activity implements OnClickListener  {
	
    public Action actionToPerform = new Action();
    
    public TextView placeInfo;
    public Button actionButton, cancelButton;
    
    public String modifiersDescription = "";


	@Override
	public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  
	  setContentView(R.layout.placedialog);
	  
	  registerViews();
	  setupOnClickListeners();
	  
	  this.setTitle(Utils.activePlace.name);
	  
	  actionToPerform = Utils.nextAction;
	  
	  if(actionToPerform.mPH > 0){
		  modifiersDescription += "Your health will get better. ";
	  }
	  else if (actionToPerform.mPH < 0) {
		  modifiersDescription += "Your health will get worse. ";
	  }
	  
	  if(actionToPerform.mMH > 0){
		  modifiersDescription += "Your mind will be clearer. ";
	  }
	  else if (actionToPerform.mMH < 0) {
		  modifiersDescription += "You might get some bad thoughts. ";
	  }
	  
	  if(actionToPerform.mMO > 0){
		  modifiersDescription += "You'll have some fun. ";
	  }
	  else if (actionToPerform.mMO < 0) {
		  modifiersDescription += "Your mood will go down. ";
	  }
	  
	  if(actionToPerform.mCA > 0){
		  modifiersDescription += "You will get some money. ";
	  }
	  else if (actionToPerform.mCA < 0) {
		  modifiersDescription += "You have to pay some money. ";
	  }
	  
	  placeInfo.setText(Utils.activePlace.desc + "\n\nYou can " + actionToPerform.name + " here. " + modifiersDescription);
	  
	  actionButton.setText(actionToPerform.name);
	  
	}
	
	
//	private void loadPrefs() {
//		
//		String actionName;
//		
//    	preferences  = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
//    	
//    	actionName = preferences.getString("nextActionName", "");
//    	
//    	Log.d("DIALOG","loaded: " + actionName);
//    	
//    	actionToPerform = Utils.nextAction;
//    	
//    	actionToPerform = Utils.getActionByName(actionName);
//    	Log.d("DIALOG","action: " + actionToPerform.name);
//        
//	}
	
	
	private void registerViews() {
			
		 actionButton = (Button) this.findViewById(R.id.place_action_button);
		 cancelButton = (Button) this.findViewById(R.id.place_cancel_button);
		 placeInfo = (TextView) this.findViewById(R.id.place_dialog_info);
		 
	}

	
	public void setupOnClickListeners() {
        
		actionButton.setOnClickListener(this);
		cancelButton.setOnClickListener(this);

    }
    
	
    public void onClick(View V) {
    	
    	switch(V.getId()) {
    	
    	case R.id.place_action_button:
    		
    		// COMPUTES ACTION
    		Log.d("TAKE ACT","confirmed");
    		
    		// CLOSES THE DIALOG
    		finish();
    		
    		break;
    		
    	case R.id.place_cancel_button:
    		
    		// CANCELS ACTION
    		
    		
    		// CLOSES THE DIALOG
    		finish();
    		
    		break;
    		
    	}

    }
    
    
    
    public void finishActivity() {
    	this.finish();
    }

}

